package ${packageCode}.func.vx.${moduleMapperCode}.${businessCode?uncap_first};

import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Table;
import ${packageCode}.${moduleMapperCode}.service.${businessCode}Service;
import com.google.common.collect.Lists;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.springframework.stereotype.Component;
import top.cardone.context.ApplicationContextHolder;
import top.cardone.core.CodeException;
import top.cardone.core.util.func.Func1;

import java.util.List;
import java.util.Map;

/**
 * ${businessName!} - 批量更新
 */
@Component("/vx/${moduleMapperCode}/${businessCode?uncap_first}/u0002.json")
public class U0002Func implements Func1<Object, Map<String, Object>> {
    private Table<String, String, String> inputConfigTable;

    public U0002Func() {
        inputConfigTable = HashBasedTable.create();
<#if (entityMapper??) && (entityMapper.fieldMapperMap??)>
    <#list entityMapper.fieldMapperMap?values as fieldMapper>
		inputConfigTable.put("${fieldMapper.code}", "funcBeanId", "escapeSqlFunc");
    </#list>
</#if>

<#if (entityMapper??) && (entityMapper.fieldMapperMap??)>
    <#list entityMapper.fieldMapperMap?values as fieldMapper>
		inputConfigTable.put("${fieldMapper.columnName}", "newName", "${fieldMapper.code}");
    </#list>
</#if>
    }

    @Override
    public Object func(Map<String, Object> inputMap) {
        List<Map<String, Object>> updateMapList = (List<Map<String, Object>>) MapUtils.getObject(inputMap, "datas");

        List<Map<String, Object>> newUpdateMapList = top.cardone.context.util.ListUtils.newArrayList(updateMapList, inputConfigTable);

        validate(newUpdateMapList);
		
        return ApplicationContextHolder.getBean(${businessCode}Service.class).updateListCache(Lists.newArrayList(newUpdateMapList));
    }

    private void validate(List<Map<String, Object>> updateList) {
        if (CollectionUtils.isEmpty(updateList)) {
            throw new CodeException("${businessName!}创建集合不能为空值!");
        }

        for (Map<String, Object> update : updateList) {
            validate(update);
        }
    }

    private void validate(Map<String, Object> update) {

    }
}